/*******************************************************************************
 * @file Food.cpp
 * Implementation of methods for class CFood
 * 
 * @package Dining.
 * 
 * @author mk
 * @date 03/01/2008 13:50:21
 * @version 0.1
 ******************************************************************************/

#include "Food.h"
#include "LockingPtr.h"
#include "Assert.h"
#include "Logging.h"
#include "Globals.h"

using namespace Dining;

bool CFood::Take(unsigned int anAmount)
{
	TRACE_FUNC("CFood::Take");

	/** Check if the desired amount is really available. */
	if (m_Amount >= anAmount)
	{
		m_Amount -= anAmount;
		return true; // flag that the portion can be consumed
	}
	
	return false; // flag that nothing can be consumed
}

bool CFood::Take(unsigned int anAmount) volatile
{
	TRACE_FUNC("CFood::Take");
	
	LockingPtr<CFood> self(*this, m_Mutex);
    return self->Take(); // invokes the non-volatile function
}

unsigned int CFood::GetAmount()
{
	TRACE_FUNC("CFood::GetAmount");	
	
	return m_Amount;
}

unsigned int CFood::GetAmount() volatile
{
	TRACE_FUNC("CFood::GetAmount");
	
	LockingPtr<CFood> self(*this, m_Mutex);
    return self->GetAmount(); // invokes the non-volatile function
}
